package queens.exceptions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

import queens.util.Utilidades;

public class QueensExceptionHandler extends ExceptionHandler{
	
	private static Log log = LogFactory.getLog(QueensExceptionHandler.class);

	public QueensExceptionHandler() {
		super();
	}
	
	public ActionForward execute(Exception e,
								 ExceptionConfig ae, 
								 ActionMapping mapping, 
								 ActionForm formInstance, 
								 HttpServletRequest request, 
								 HttpServletResponse response) throws javax.servlet.ServletException {
		
		log.info("Exception recogida por el handler");
		String stackTrace = Utilidades.printStackTrace(e);
		log.info(stackTrace);
		
		request.setAttribute("trace", stackTrace);
		
		return mapping.findForward("error");
		
	}
}